* -----------------------------------------------------------
* Date: July 29, 2021
* Purpose: IVR survey attrition analysis
* Output: 56 tables analysing compliance. Tables stored under
* 		  tables/compliance
* -----------------------------------------------------------
clear
set more off

* -----------------------------------------------------------
use "${final}/oisl_clean_data.dta", clear
 replace savings_base=savings_base/100

keep if month==8
drop if treatment == 0


est clear
foreach c in 3 any 5 7{
	
	eststo: reg complete_calc_`c' female age_100 age2_10000 loan accra savings_base savings2_base missing_gender missing_age, cluster(id)
	quietly summ complete_calc_`c'
	estadd scalar r(mean)
	
}

esttab using "${output}/complete_calc_baseline_long.tex", replace /*
*/	   sfmt(%12.3fc) number booktabs f b(3) se(3) label depvars/*
*/	   star(* 0.1 ** 0.05 *** 0.01)							/*
*/	   keep(female age_100 age2_10000 loan accra savings_base savings2_base) /*
*/	   order(female age_100 age2_10000 loan accra savings_base savings2_base)/*	
*/	   coeflabel(female "Female" /*
*/				 age_100 	"$\text{Age} /$ 100"/*
*/				 age2_10000 "$\text{Age}^2 /$ 10,000"/*
*/				 loan   "Loan Client"/*
*/	 			 accra  "Lives in Accra"/*
*/				 savings_base "Savings" savings2_base "Savings squared") /*
*/ 	   mtitles("3 Messages" "Any Messages" "5 Messages" "7 Messages") /*
*/     collabels(none) compress /*
*/	   scalars("N Observations" "F F statistic" /*
*/			   "p p-value" "mean Mean Compliance") 


* Randomisation

est clear
foreach c in 3 any 5 7{
	
	eststo: reg complete_calc_`c' treatment_3 i.strata, cluster(id)
	quietly summ complete_calc_`c' if treatment == 1
	estadd scalar r(mean)
	
}

esttab using "${output}/complete_calc_treat_long.tex", replace /*
*/	   sfmt(%12.3fc) number booktabs f b(3) se(3) label depvars/*
*/	   star(* 0.1 ** 0.05 *** 0.01)							/*
*/	   keep(treatment_3 ) /*
*/	   order(treatment_3 )/*	
*/	   coeflabel(treatment_3 "Treatment" /*
*/				 2.strata "Stratum 2" /*
*/				 3.strata "Stratum 3" /*
*/				 4.strata "Stratum 4") /*
*/ 	   mtitles("3 Messages" "Any Messages" "5 Messages" "7 Messages") /*
*/     collabels(none) compress /*
*/	   scalars("N Observations" "F F statistic" /*
*/			   "p p-value" "mean Mean Compliance (Placebo)") 


